from concurrent.futures import ThreadPoolExecutor
import tornado.web
import sys
from tornado import gen, web, ioloop
from tornado.concurrent import run_on_executor
sys.path.append("../")
from services import MyDb, MyCache
from logic.ipDao import ipDao
#博客基类

class baseHttp (tornado.web.RequestHandler):
    executor = ThreadPoolExecutor(20)

    @gen.coroutine
    def initialize(self):
        self.cache = MyCache().session()
        yield  self.logsave()

    @run_on_executor
    def logsave(self):
        if self.cache.get(self.request.remote_ip) == None:
            self.cache.expire()
            self.cache.add(self.request.remote_ip,self.request.headers.get("User-Agent","鬼知道"),expire=60,tag="ip-log")
            ipDao().saveLog(self.request.remote_ip,self.request.uri,self.request.headers.get("User-Agent","鬼知道"))
